package com.cskaoyan.user.controller;

import com.cskaoyan.mall.commons.result.ResponseData;
import com.cskaoyan.mall.commons.result.ResponseUtil;
import com.cskaoyan.user.form.UserRegisterRequest;
import com.cskaoyan.user.service.IUserRegisterService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@RestController
@RequestMapping("user")
public class RegisterController {

    @Autowired
    CaptchaController captchaController;

    @Autowired
    IUserRegisterService registerService;

    @PostMapping("register")
    public ResponseData register(@RequestBody UserRegisterRequest registerRequest, HttpServletRequest httpServletRequest){
        // 验证激活码，由于需要传递request，没写进service
        String captcha = registerRequest.getCaptcha();
        captchaController.validKaptchaCode(captcha, httpServletRequest);

        // 没问题就交给service层
        registerService.register(registerRequest);
        return new ResponseUtil<>().setData(null);
    }
}
